package com.lykj.llw.box.adapter

import androidx.constraintlayout.widget.ConstraintLayout
import com.blankj.utilcode.util.BusUtils
import com.blankj.utilcode.util.ColorUtils
import com.blankj.utilcode.util.ConvertUtils
import com.blankj.utilcode.util.TimeUtils
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.viewholder.BaseViewHolder
import com.lykj.llw.box.R
import com.lykj.llw.box.data.bean.response.MyCouponListResponse
import com.lykj.llw.box.data.bean.response.MyCouponResponse
import java.text.SimpleDateFormat

/**
 * ================================================
 * 我的优惠券列表适配器
 * ================================================
 *
 * @author gosha
 * @date 2023/10/17-13:38
 */
class MyCouponAdapter :
    BaseQuickAdapter<MyCouponResponse.DataDTO.RowsDTO, BaseViewHolder>(R.layout.item_coupon, null) {
    private var mType = 0 //type 0:未使用 1:已使用 2:已过期
    val sdfs = SimpleDateFormat("yyyy-MM-dd HH:mm:ss")
    val sdfd = SimpleDateFormat("yyyy/MM/dd")

    open fun setType(type: Int) {
        mType = type
    }

    override fun convert(holder: BaseViewHolder, item: MyCouponResponse.DataDTO.RowsDTO) {
        when (mType) {
            0 -> {
                holder.getView<ConstraintLayout>(R.id.clt_root)
                    .setBackgroundResource(R.mipmap.bg_coupon_normal)

                holder.setTextColor(R.id.tv_summery, ColorUtils.getColor(R.color.blue_FF664FC3))
            }

            1 -> {
                holder.getView<ConstraintLayout>(R.id.clt_root)
                    .setBackgroundResource(R.mipmap.bg_coupon_normal)
                holder.getView<ConstraintLayout>(R.id.clt_root).alpha = 0.6f

                holder.setTextColor(R.id.tv_summery, ColorUtils.getColor(R.color.blue_FF664FC3))
            }

            2 -> {
                holder.getView<ConstraintLayout>(R.id.clt_root)
                    .setBackgroundResource(R.mipmap.bg_coupon_other)

                holder.setTextColor(R.id.tv_summery, ColorUtils.getColor(R.color.grey_FF787878))
            }
        }

        holder.setText(R.id.tv_amount, "${item.couponMoney}")
        holder.setText(R.id.tv_limit_desc, "满${item.payMoney}可用")
        holder.setText(R.id.tv_name, "${item.couponName}")
        holder.setText(R.id.tv_summery, "${item.gameName}")

        holder.setText(R.id.tv_date, "有效期：${sdfd.format(sdfs.parse(item.startTime))}-${sdfd.format(sdfs.parse(item.endTime))}")
    }
}